#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
const int N = 1e6 + 5;

int n;
vector<int> a;

void solve() {
    a.resize(n);
    stack<int> st;
    ll ans=-1;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        while (!st.empty() && a[i] <= a[st.top()]) {
            int h = a[st.top()];
            st.pop();
            int l = st.empty() ? -1 : st.top();
            int w = i - l - 1;
            ans = max((ll)h * w, ans);
        }
        st.push(i);
    }
    while (!st.empty()) {
        int top_idx = st.top();
        st.pop();
        int h = a[top_idx];
        int l = st.empty() ? -1 : st.top();
        int w = n - l - 1;
        ans = max((ll)h * w, ans);
    }
    printf("%lld\n",ans);
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    while(scanf("%d",&n)&&n!=0)solve();

    return 0;
}